//
//  LSHomePageViewController.m
//  lightSpot
//
//  Created by lightSpot on 2022.
//  Copyright © 2022 lightSpot. All rights reserved.
//

#import "LSHomePageViewController.h"

#import "LSSetUpViewController.h" //设置
#import "LSMattingViewController.h" //抠图
#import "LSVideoScreenshotViewController.h" //视频截图
#import "LSExtensionQueryViewController.h" //扩展名查询
#import "LSSubscribeViewController.h"

#import "LSHomeFunctionCell.h"

@interface LSHomePageViewController ()

@end

@implementation LSHomePageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.view.backgroundColor = UIColorFromHex(0xE9EDF9);
    self.leftItem.hidden = YES;
    [self setRightItemWithIcon:[UIImage imageNamed:@"home_set"] selector:@selector(gotoSetUpViewController)];
    [self.view bringSubviewToFront:self.navigationBar];
    
    [self.tableView registerNib:[UINib nibWithNibName:@"LSHomeFunctionCell" bundle:nil] forCellReuseIdentifier:@"LSHomeFunctionCell"];
    
    self.tableView.frame = CGRectMake(0,-self.statusBarHeight, kScreenWidth,kScreenHeight + self.statusBarHeight);
    
    if (!kUserManager.userManager.isSubscribe) {

        if (![[[NSUserDefaults standardUserDefaults] objectForKey:@"isFirstEnter"] boolValue]) {
            LSSubscribeViewController *vc = [LSSubscribeViewController new];
            vc.modalPresentationStyle = UIModalPresentationFullScreen;
            [self.navigationController presentViewController:vc animated:YES completion:nil];
        }
    }
}

#pragma mark - cellDataSource

- (NSArray *)cellDataSource {
    
    if (!self.dataSource) {
        NSMutableArray *arr = [NSMutableArray arrayWithCapacity:4];
        
        __block NSMutableArray *subarr = nil;
        __block NSDictionary *dict = nil;

        subarr = [NSMutableArray arrayWithCapacity:1];
                
        dict =  @{@"class":LSHomeFunctionCell.class,
                  @"height":@([LSHomeFunctionCell getCellFrame:[NSNumber numberWithFloat:kScreenWidth*812/375]]),
                  @"delegate":@YES};
        [subarr addObject:dict];

        [arr addObject:subarr];
        
        self.dataSource = arr;
    }
    return self.dataSource;
}

#pragma mark LSHomeFunctionCellDelegate 抠图 视频截图 扩展名查询

- (void)homeFunctionCell:(LSHomeFunctionCell *)cell button:(UIButton *)sender {
    if (!kUserManager.userManager.isSubscribe) {
        [self gotoSubscribeViewController];
        return;
    }
    
    if (sender.tag == 10) {
        //抠图
        [self gotoMattingViewController];
    } else if (sender.tag == 11) {
        //视频截图
        [kMediaManager requestPhotoAuthorizationStatus:^(BOOL granted) {
            if (granted) {
                [self gotoVideoScreenshotViewController];
            } else {
                [kMediaManager showAlertViewAboutNotAuthorAccessPhoto];
            }
        }];
        
    } else if (sender.tag == 12) {
        //扩展名查询
        [self gotoExtensionQueryViewController];
    }
}

#pragma mark - goto

//设置
- (void)gotoSetUpViewController {
    LSSetUpViewController* vc = [LSSetUpViewController new];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}

//抠图
- (void)gotoMattingViewController {
    LSMattingViewController *vc = [[LSMattingViewController alloc] init];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}

//视频截图
- (void)gotoVideoScreenshotViewController {
    LSVideoScreenshotViewController* vc = [LSVideoScreenshotViewController new];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}

//扩展名查询
- (void)gotoExtensionQueryViewController {
    LSExtensionQueryViewController* vc = [LSExtensionQueryViewController new];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}

@end
